﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataWinner.Entity.Nba_Sina.Models;
using DataWinner.Nba.DataAccess.Sina;
using DataWinner.Nba.Model.Portal;

namespace DataWinner.Business.Portal
{
    public class BsMatchList
    {
        DaMatch daMatch = new DaMatch();
        DaTeamStat daTeamStat = new DaTeamStat();

        public List<MatchListItemModel> GetMatchListItemModelSet(DateTime dateTime)
        {
            List<MatchListItemModel> result = new List<MatchListItemModel>();

            DateTime dateBegin = DateTime.Parse(dateTime.Year + "-" + dateTime.Date.Month + "-1");
            DateTime dateEnd = DateTime.Parse(dateBegin.AddMonths(1).Year + "-" + dateBegin.AddMonths(1).Month + "-1");

            List<Match_Sina> matchSet = daMatch.GetMatchListByDate(dateBegin, dateEnd).OrderBy(m=>m.MatchTime).ToList();

            List<TeamStat_Sina> teamStatSet = daTeamStat.GetTeamStatByMatchDate(dateBegin, dateEnd).ToList();

            foreach (Match_Sina match in matchSet)
            {
                result.Add(new MatchListItemModel() { 
                    Match = match,
                    HomeTeamStat = teamStatSet.Where(t=>t.MatchId == match.MatchId && t.TeamId == match.Team_Sina.TeamId).FirstOrDefault(),
                    VisitingTeamStat = teamStatSet.Where(t=>t.MatchId == match.MatchId && t.TeamId == match.Team_Sina1.TeamId).FirstOrDefault()
                });
            }

            return result;
        }
        
    }
}
